<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        *{
            margin:0;padding:0;
        }
        ul{
            list-style-type: none;
            line-height: 50px;
            background: #5f5f5f;
            font-size: 0;
        }
        li{
            display: inline-block;
            color:#fff;
            font-size:16px;
            width:100px;
            cursor: pointer;
            vertical-align: bottom;
            text-align: center;
        }
        .current{
            background: #4caf50;
        }
        li:hover{
            background: #000;
        }
    </style>
</head>

<body>
    <ul>
        <li class="current">HTML</li>
        <li>CSS</li>
        <li>JavaScript</li>
    </ul>
    <script>
        // window.onload = function(){
            var lis = document.getElementsByTagName("li");
            for(var i=0;i<lis.length;i++){
                lis[i].onclick = function(){
                    for(let i=0;i<lis.length;i++){
                        lis[i].style.backgroundColor="#5f5f5f"
                    }
                    this.style.backgroundColor="#4caf50"
                }
                

            }
        // }
        
    </script>
</body>
</html>